package com.example.back.controller;

import com.example.back.model.Food;
import com.example.back.service.FoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : 贾媛晴
 * @createTime : 2022/4/29 17:27
 */
@RestController
@Api(tags = "FoodController")
@CrossOrigin //允许跨域
public class FoodController {

    @Autowired
    FoodService foodService;
    @ApiOperation("查询美食")
    @GetMapping("/Food")
    public List<Food> selectAll(){
        List<Food> foodList = this.foodService.selectAll();
        return foodList;
    }
    @ApiOperation("查询收藏的美食")
    @GetMapping("/Conleection_Food")
    public Food selectFood(String foodname){
        Food collecton_foodList = this.foodService.selectFood(foodname);
        return collecton_foodList;
    }

    @ApiOperation("后台编辑美食信息")
    @PostMapping("/Edit _Food")
    public int updateArea(int id, String name, String fooddes){
        return this.foodService.updateFood(id,name,fooddes);
    }

    @ApiOperation("后台删除美食信息")
    @GetMapping("/Delete_Food")

    public int deleteArea(int id) {
        return this.foodService.deleteFood(id);
    }

    @ApiOperation("后台添加美食信息")
    @GetMapping("/Insert_Food")
    public int insertArea( String name, String fooddes) {
        return this.foodService.insertFood(name,fooddes);
    }



}
